<!doctype html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
	<head>
		<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
		<meta http-equiv="content-script-type" content="text/javascript">
		<meta http-equiv="content-style-type" content="text/css">
		<meta name="author" content="Heidi Rakels">
		<meta name="description" content="Sanaware Java Docking - Developer guide - Visualizers">
		<link rel="stylesheet" type="text/css" href="../style.css">
		<title>How to Use Visualizers (Minimizers and Maximizers)</title>
	</head>
<body>

<div class="nextprev">
<nobr><a href="compositedock.html">&laquo; prev</a></nobr>
<nobr><a href="dockmodel.html">next &raquo;</a></nobr>
</div>

<span class="item"><a href="../main/index.html">Java Docking Home</a></span>&gt;
<span class="item"><a href="index.html">Developer Guide</a></span>&gt;
<span class="selected item">Visualizers (Minimizers, Maximizers, and Externalizers)</span>

<h2>
How to Use Visualizers (Minimizers, Maximizers, and Externalizers)
</h2>

<h3>
:: Visualizers ::
</h3>
<p>
A <a href="../javadoc/com/javadocking/visualizer/Visualizer.html" target="_blank">Visualizer</a> 
shows a <a href="../javadoc/com/javadocking/dockable/Dockable.html" target="_blank">Dockable</a>
in a special state. The special state is usually 
<a href="../javadoc/com/javadocking/dockable/DockableState.html#MAXIMIZED" target="_blank">DockableState.MAXIMIZED</a> or 
<a href="../javadoc/com/javadocking/dockable/DockableState.html#MINIMIZED" target="_blank">DockableState.MINIMIZED</a>.
</p>
<p>
We call a visualizer that shows a dockable in the state MAXIMIZED a maximizer.
We call a visualizer that shows a dockable in the state MINIMIZED a minimizer.
</p>
<p>
Visualizers have to be registered in the dock model with a key:
<blockquote><pre>
		dockModel.addVisualizer("minimizer", minimizePanel, frame);
</pre></blockquote>
</p>

<h3>
:: Using a simple minimizer, maximizer, and externalizer ::
</h3>
<p>
A very simple minimizer is <a href="../javadoc/com/javadocking/visualizer/LineMinimizer.html" target="_blank">LineMinimizer</a>. 
It shows the minimized dockables in a line at the bottom of a panel.<br/>
The maximizer that is usually used is a <a href="../javadoc/com/javadocking/visualizer/SingleMaximizer.html" target="_blank">SingleMaximizer</a>. 
It shows one maximized dockable in a panel.<br/>
The externalizer that is usually used is a <a href="../javadoc/com/javadocking/visualizer/FloatExternalizer.html" target="_blank">FloatExternalizer</a>. 
</p>
<p>
In this example there is a minimizer around the root dock. Around the minimizer is a maximizer.
<blockquote><pre>
		// Create an externalizer.
		FloatExternalizer externalizer = new FloatExternalizer(frame);
		dockModel.addVisualizer("externalizer", externalizer, frame);

		// Create a minimizer.
		LineMinimizer minimizePanel = new LineMinimizer(splitDock);
		dockModel.addVisualizer("minimizer", minimizePanel, frame);
		
		// Create a maximizer.
		SingleMaximizer maximizePanel = new SingleMaximizer(minimizePanel);
		dockModel.addVisualizer("maximizer", maximizePanel, frame);
		
		...
		
		// Minimize dockables.
		minimizer.visualizeDockable(dockable5);
		minimizer.visualizeDockable(dockable6);
		minimizer.visualizeDockable(dockable7);
		minimizer.visualizeDockable(dockable8);
		
		// Externalize dockable.
		//externalizer.visualizeDockable(dockable9);
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		Point location = new Point((screenSize.width - 200) / 2, (screenSize.height - 200) / 2);
		externalizer.externalizeDockable(dockable9, location);
		
</pre></blockquote>
</p>

<a name="DockingMinimizer"><!-- --></a>
<h3>
:: Using a docking minimizer ::
</h3>
<p>
A more complicated minimizer is <a href="../javadoc/com/javadocking/visualizer/DockingMinimizer.html" target="_blank">DockingMinimizer</a>. 
It shows the minimized dockables in lines at the borders of a border dock. 
The minimized dockables can move in their lines, be dragged to other lines, 
or even be made floating.
</p>
<p>
In this example there is a maximizer around the root dock. Around the maximizer is a docking minimizer.
The minimizer uses a border dock in mode MODE_MINIMIZE_BAR. This dock is a root dock and has to be registered
in the dock model as root dock:
<blockquote><pre>
		// Create a maximizer and add it to the dock model.
		SingleMaximizer maximizePanel = new SingleMaximizer(splitDock);
		dockModel.addVisualizer("maximizePanel", maximizePanel, frame);
		
		// Create a docking minimizer.
		BorderDock borderDock = new BorderDock(new ToolBarDockFactory());
		borderDock.setMode(BorderDock.MODE_MINIMIZE_BAR);
		borderDock.setCenterComponent(maximizePanel);
		BorderDocker borderDocker = new BorderDocker();
		borderDocker.setBorderDock(borderDock);
		DockingMinimizer minimizer = new DockingMinimizer(borderDocker);
		
		// Add the minimizer to the dock model, add also the border dock used by the minimizer to the dock model.
		dockModel.addVisualizer("minimizePanel", minimizer, frame);
		dockModel.addRootDock("minimizerBorderDock", borderDock, frame);
		
		// Add the border dock of the minimizer to this panel.
		this.add(borderDock, BorderLayout.CENTER);
		
		// Minimize dockables 5, 6, 7, and 8.
		minimizer.visualizeDockable(dockable5);
		minimizer.visualizeDockable(dockable6);
		minimizer.visualizeDockable(dockable7);
		minimizer.visualizeDockable(dockable8);
</pre></blockquote>
</p>

<h3>
:: Create a custom minimizer ::
</h3>
<p>
If you want to minimize your dockables in a different way, you have to create your own visualizer implementation.
This is shown in WindowMinimizerExample. The minimizer shows its minimized components in a dialog.
</p>

<h3>
:: Headers used by minimizers and maximizers ::
</h3>
<p>
When a dockable is maximized, a maximize header is displayed above the dockable.
When a dockable is minimized, the dockable is represented by a minimize header.
The <a href="../javadoc/com/javadocking/component/SwComponentFactory.html" target="_blank">SwComponentFactory</a>
is responsible for creating those headers:
<ul>
<li><a href="../javadoc/com/javadocking/component/SwComponentFactory.html#createMaximizeHeader(com.javadocking.dockable.Dockable, int)" target="_blank">SwComponentFactory.createMaximizeHeader(com.javadocking.dockable.Dockable, int)</a></li>
<li><a href="../javadoc/com/javadocking/component/SwComponentFactory.html#createMinimizeHeader(com.javadocking.dockable.Dockable, int)" target="_blank">SwComponentFactory.createMinimizeHeader(com.javadocking.dockable.Dockable, int)</a></li>
</ul>
The following example uses a little image of the dockable component, when the dockable is minimized:
<blockquote><pre>
	...
	
		// Set our custom component factory that creates headers for minimized dockables with an image.
		DockingManager.setComponentFactory(new CustomComponentFactory());

	...

	/**
	 * The header of a minimized dockable will be an image of the dockable component.
	 */
	private class CustomComponentFactory extends DefaultSwComponentFactory
	{

		// Overwritten methods.

		public SelectableHeader createMinimizeHeader(Dockable dockable, int position)
		{
			return new ImageMinimzeHeader(dockable, position);
		}
		
	}
</pre></blockquote>
</p>
<br/>

<hr>

<br/>
The source code of the samples can be found in:
<br/><br/>
<table>
<tr>
	<td><a href="code/VisualizersExample.java.html">VisualizersExample</a></td><td>Shows the usage of a minimizer, maximizer, and externalizer.</td>
</tr>
<tr>
	<td><a href="code/DockingMinimizerExample.java.html">DockingMinimizerExample</a></td><td>Shows the usage of a docking minimizer.</td>
</tr>
<tr>
	<td><a href="code/ImageDockingMinimizerExample.java.html">ImageDockingMinimizerExample</a></td><td>Shows the usage of a docking minimizer with images.</td>
</tr>
<tr>
	<td><a href="code/WindowMinimizerExample.java.html">WindowMinimizerExample</a></td><td>Shows the creation of a new minimizer.</td>
</tr>
<tr>
	<td><a href="code/ExternalizerExample.java.html">ExternalizerExample</a></td><td>Shows the usage of an externalizer.</td>
</tr>
</table>

<br/>
<hr>
<br/>

<div class="nextprevbottom">
<nobr><a href="compositedock.html">&laquo; prev</a></nobr>
<nobr><a href="dockmodel.html">next &raquo;</a></nobr>
</div>

</body>

</html>